<?php
declare (strict_types = 1);

namespace app\admin\controller\admin;

use think\facade\Request;
use think\facade\View;
use app\common\service\AdminZccandidate as S;
use app\common\model\AdminZccandidate as M;

class Zccandidate extends  \app\admin\controller\Base
{
    protected $middleware = ['AdminCheck','AdminPermission'];

    // 列表
    public function index(){
        $biaoid = input('id');
        View::assign('biaoid', $biaoid);
        $wjy = S::goWjy($biaoid);
        View::assign('wjy', $wjy['wjy']);
        $ywfenzu = S::goBianhaofenzu($biaoid);
        View::assign('ywfenzu', $ywfenzu['fenzu']);
        if (Request::isAjax()) {
            return $this->getJson(M::getList($biaoid));
        }
        return $this->fetch();
    }

    // 添加
    public function add(){
        $biaoid = input('biaoid');
        View::assign('biaoid', $biaoid);
        if (Request::isAjax()) {
            return $this->getJson(S::goAdd(Request::post()));
        }
        return $this->fetch();
    }

    // 编辑
    public function edit($id){
        if (Request::isAjax()) {
            return $this->getJson(S::goEdit(Request::post(),$id));
        }
        return $this->fetch('',['model' => M::find($id)]);
    }

    // 状态
    public function status($id){
        return $this->getJson(S::goStatus(Request::post('status'),$id));
        }

    // 删除
    public function remove($id){
        return $this->getJson(S::goRemove($id));
        }

    // 批量删除
    public function batchRemove(){
        return $this->getJson(S::goBatchRemove(Request::post('ids'),Request::post('biaoid')));
        }

    // 回收站
    public function recycle(){
        if (Request::isAjax()) {
            return $this->getJson(S::goRecycle());
        }
        return $this->fetch();
    }

    // 编号分组
    public function bianhaofenzu($biaoid){
        return S::goBianhaofenzu($biaoid);
    }

    // 状态
    public function state($id){
        return S::goState($id);
    }

    // 改票
    public function gaipiao($id,$numpiao){
        return S::goGaipiao($id,$numpiao);
    }

    // 导出候选数据
    public function getdata($biaoid,$daochufenzu){
        return S::goGetdata($biaoid,$daochufenzu);
    }

    // 得票统计
    public function depiaotongji($id){
        View::assign('id',$id);
        $jinripiao = S::goDepiaotongji($id);
        View::assign('jinripiao',$jinripiao['jinripiao']);
        View::assign('shuju',$jinripiao['shuju']);
        return $this->fetch();
    }  
    
    // 得票统计数据
    public function depiaotongjishuju($id,$data){
        return S::goDepiaotongjishuju($id,$data);
    }  

    // 清空数据
    public function qingkongshuju($id){
        return S::goQingkongshuju($id);
    }  

}
